module SOD
  
  class SketchInfoContainer
    
    attr_accessor :footprintLength, :footprintWidth
    attr_accessor :pointOfOrigin, :direction
    attr_accessor :footprintPoints, :update
    
    def initialize
      @footprintLength = 0.0.m
      @footprintWidth = 0.0.m
      @pointOfOrigin = Geom::Point3d.new
      @direction = Geom::Vector3d.new
      @footprintPoints = []
    end
    
    def update
      @footprintPoints.each { |p| puts "point " + p.to_s } if $debug
      vec1 = (@footprintPoints[1] - @footprintPoints[0])
      vec2 = (@footprintPoints[2] - @footprintPoints[1])
      puts clockwise = self.clockwise?(vec1, vec2) if $debug
      
      dist1 = vec1.length
      dist2 = vec2.length
      
      if (dist1 > dist2)
        @footprintLength = dist1
        @footprintWidth = dist2
        if clockwise
          @pointOfOrigin = @footprintPoints[1]
          @direction = vec1.normalize!.reverse!
        else
          @pointOfOrigin = @footprintPoints[0]
          @direction = vec1.normalize!
        end
        puts "SIC.update: 1st Option" if $debug
      else
        @footprintLength = dist2
        @footprintWidth = dist1
        if clockwise
          @pointOfOrigin = @footprintPoints[2]
          @direction = vec2.normalize!.reverse!
        else
          @pointOfOrigin = @footprintPoints[1]
          @direction = vec2.normalize!
        end
        puts "SIC.update: 2nd Option" if $debug
      end
      puts "origin: " + @pointOfOrigin.to_s if $debug
      puts "direction: " + @direction.to_s if $debug
      puts "length: " + @footprintLength.to_s if $debug
      puts "width" + @footprintWidth.to_s if $debug
    end
    
      def clockwise?(vector1, vector2)
        cross = vector1 * vector2
        if cross.z > 0
          return false
        else
          return true
        end
      end
    
  end
  
end
